<?php

/**
 * 作者：lucas
 * 链接：
 * 邮箱：dissipator_520@qq.com
 */

/**
 * ExportAction
 *
 * @author lucas
 */
class ExportAction extends BaseAction {

    public function index() {
        $this->display();
    }

    public function getData() {

        $Mode = M('export');
        $data = $Mode->where($this->condition)->page($this->page, $this->rows)->order($this->order)->select();
        // Log::write($Mode->getLastSql());
        $this->returnGridData($data, $Mode->where($this->condition)->count());

    }

    public function toAdd() {

        $fields=array('手册号','自编号','报关单','TRACK','SOT23QTY','SOT23MY','SOT89QTY','SOT89MY','EP3QTY','EP3MY','Addre','Carrier','备注');
        foreach ($fields as $key => $value) {
                    switch ($value)
                    {
                    case '手册号':
                        $output .= '
                        <tr>
                            <td>' .$value .':</td>
                            <td valign="middle" colspan="2">
                            <input id="mm" class="easyui-combobox" name="'.$value.'" style="width:150px;"  
                                    data-options="
                                    valueField:\'手册名称\',
                                    textField:\'手册名称\',
                                    url:\'__ROOT__/import/getmData\'
                                    " />  
                            </td>
                        </tr>';
                        break; 
                    case 'fhdate':
                        $output .= '<tr><td>' .$value .'：</td><td><input name="'.$value.'"class="easyui-datebox"  required="required" type="text" value="" style="width: 150px;"/></td></tr>';
                      break;
                    default:
                        $output .= '<tr><td>' .$value .'：</td><td><input name="'.$value.'"class="easyui-textbox" value="" style="width: 150px;"/></td></tr>';
                    }

            $data['output']= $output;

            // echo  $output;
            $this->assign('data',$data);
        }
        $this->display('add');
    }

    public function doSave() {
        // p($_POST);
        // die;
        $Model = M("export");

        if (!$Model->create()) {
            $this->returnStatus(false, $Model->getError());
        } else {
            if (empty($Model->ID)) {
                $Model->add();
                Log::write($Mode->getLastSql());
            } else {
                $Model->save();
                // Log::write($Mode->getLastSql());
            }

            if ($Model->getError()) {
                $this->returnStatus(false, $Model->getError());
            }
            $this->returnStatus();
        }
        // p ($_POST);
    }

    public function doDelete() {
        $ids = $_POST['ids'];
        $array = explode(',', $ids);
        // p($array);
        if ($array && count($array) > 0) {
            $Model = M("export");
            foreach ($array as $id) {
                $Model->where('ID = %d', $id)->delete();
            }
        }
        $this->returnStatus();
    }


    public function toUpdate() {
        $ID = $_GET['ID'];
        $field=array('ID','手册号','自编号','报关单','TRACK','SOT23QTY','SOT23MY','SOT89QTY','SOT89MY','EP3QTY','EP3MY','Addre','Carrier','备注');
        if ($ID) {
            $Model = M('export');
            $data = $Model->where('ID = %d', $ID)->field($field)->find();
            // p($data);
            if ($data) {
                foreach ($data as $key => $value) {
                    switch ($key)
                    {
                    case 'ID':
                        $output .= '<input name="ID" required="required" type="hidden" value="' .$value. '" style="width: 150px;"/>';

                      break; 
                    case '手册号':
                        $output .= '
                        <tr>
                            <td>' .$key .':</td>
                            <td valign="middle" colspan="2">
                            <input id="mm" class="easyui-combobox" name="'.$key.'" value="' .$value. '" style="width:150px;"  
                                    data-options="
                                    valueField:\'手册名称\',
                                    textField:\'手册名称\',
                                    url:\'__ROOT__/import/getmData\'
                                    " />  
                            </td>
                        </tr>';
                        break; 
                    case 'label2':
                      $output .= '<tr><td>' .$key .'：</td><td><input name="'.$key.'" required="required" type="text" value="' .$value. '" style="width: 150px;"/></td></tr>';
                      break;
                    default:
                    $output .= '<tr><td>' .$key .'：</td><td><input name="'.$key.'" required="required" type="text" value="' .$value. '" style="width: 150px;"/></td></tr>';
                    }
                    $data['output']=$output ;
                }
                $this->assign('data', $data);
            }
            else 
            $this->assign('data', '无效ID号请检查！');

        }
        $this->display('add');
    }

}

?>
